package com.jfinal.winxin.sdk.api;

import com.jfinal.weixin.sdk.api.AccessTokenApi;
import com.jfinal.weixin.sdk.api.ApiResult;
import com.jfinal.weixin.sdk.api.DatacubeApi;
import com.jfinal.weixin.sdk.utils.HttpUtils;
import com.jfinal.weixin.sdk.utils.JsonUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2017/5/16.
 */
public class DatacubeExtApi {
  private static String getWeAnalysisAppidDailySummaryTrendUrl = "https://api.weixin.qq.com/datacube/getweanalysisappiddailysummarytrend?access_token=";
  private static String getWeAnalysisAppidDailyVisitTrendUrl = "https://api.weixin.qq.com/datacube/getweanalysisappiddailyvisittrend?access_token=";
  private static String getWeAnalysisAppidVisitDistributionUrl = "https://api.weixin.qq.com/datacube/getweanalysisappidvisitdistribution?access_token=";
  private static String getWeAnalysisAppidDailyRetainInfoTrendUrl = "https://api.weixin.qq.com/datacube/getweanalysisappiddailyretaininfo?access_token=";
  private static String getWeAnalysisAppidVisitPageUrl = "https://api.weixin.qq.com/datacube/getweanalysisappidvisitpage?access_token=";
  /**
   * 获取统计信息
   * @param url url链接
   * @param begin_date 获取数据的起始日期，begin_date和end_date的差值需小于“最大时间跨度”（比如最大时间跨度为1时，begin_date和end_date的差值只能为0，才能小于1），否则会报错
   * @param end_date 获取数据的结束日期，end_date允许设置的最大值为昨日
   * @return ApiResult
   */
  private static ApiResult getData(String url, String begin_date, String end_date) {
    Map<String, String> mapData = new HashMap<String, String>();
    mapData.put("begin_date", begin_date);
    mapData.put("end_date", end_date);

    String jsonResult = HttpUtils.post(url, JsonUtils.toJson(mapData));
    return new ApiResult(jsonResult);
  }
  public static ApiResult getWeAnalysisAppidDailySummaryTrend(String begin_date, String end_date) {
    String url = getWeAnalysisAppidDailySummaryTrendUrl + AccessTokenApi.getAccessTokenStr();
    return getData(url, begin_date, end_date);
  }
  public static ApiResult getWeAnalysisAppidDailyVisitTrend(String begin_date, String end_date) {
    String url = getWeAnalysisAppidDailyVisitTrendUrl + AccessTokenApi.getAccessTokenStr();
    return getData(url, begin_date, end_date);
  }
  public static ApiResult getWeAnalysisAppidVisitDistribution(String begin_date, String end_date) {
    String url = getWeAnalysisAppidVisitDistributionUrl + AccessTokenApi.getAccessTokenStr();
    return getData(url, begin_date, end_date);
  }
  public static ApiResult getWeAnalysisAppidDailyRetainInfoTrend(String begin_date, String end_date) {
    String url = getWeAnalysisAppidDailyRetainInfoTrendUrl + AccessTokenApi.getAccessTokenStr();
    return getData(url, begin_date, end_date);
  }
  public static ApiResult getWeAnalysisAppidVisitPage(String begin_date, String end_date) {
    String url = getWeAnalysisAppidVisitPageUrl + AccessTokenApi.getAccessTokenStr();
    return getData(url, begin_date, end_date);
  }
}
